package com.lingyun.ucm.client.heartheat.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * 
 * @author Terrence2013
 * 2018年1月24日 上午9:43:16
 * TODO
 */
public class ClientReportQuartz {
    /**
     * 每5秒向服务端报告一次客户端自身状态
     */
    public void reportClientStatus(){
    	Scheduler scheduler = null;
    	try{
    		scheduler = new StdSchedulerFactory().getScheduler();
	        JobDetail job = JobBuilder
	                .newJob(ClientReportJob.class)
	                .withIdentity("clientReportJob", "report")
	                .build();
	        SimpleTrigger trigger = TriggerBuilder
	                .newTrigger()
	                .withIdentity("clientReportTrigger", "report")
	                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60).repeatForever())
	                .build();
	        scheduler.start();
	        scheduler.scheduleJob(job, trigger);
    	}catch(Exception ex){
    		if(null!=scheduler){
    			try {
					scheduler.shutdown(true);
				} catch (SchedulerException e) {
					e.printStackTrace();
				}
    		}
    	}
    }

    public static void main(String[] args) {
         new ClientReportQuartz().reportClientStatus();
    }

}
